<script>
  import Vue from 'vue'

  export default {
    name: 'app',
    components: {},
    created() {
      // 调用API从本地缓存中获取数据
      /*
       * 平台 api 差异的处理方式:  api 方法统一挂载到 mpvue 名称空间, 平台判断通过 mpvuePlatform 特征字符串
       * 微信：mpvue === wx, mpvuePlatform === 'wx'
       * 头条：mpvue === tt, mpvuePlatform === 'tt'
       * 百度：mpvue === swan, mpvuePlatform === 'swan'
       * 支付宝(蚂蚁)：mpvue === my, mpvuePlatform === 'my'
       */

      let logs
      if (mpvuePlatform === 'my') {
        logs = mpvue.getStorageSync({key: 'logs'}).data || []
        logs.unshift(Date.now())
        mpvue.setStorageSync({
          key: 'logs',
          data: logs
        })
      } else {
        logs = mpvue.getStorageSync('logs') || []
        logs.unshift(Date.now())
        mpvue.setStorageSync('logs', logs)
      }
      console.log("这是AppVue-create")
      // env是你云开发的环境id。
      wx.cloud.init({
        env: 'meetion-dev',
        traceUser: true
      });
      Vue.prototype.database = wx.cloud.database({env: 'meetion-dev'});

      wx.showLoading({
        title: '加载中'
      })
     wx.cloud.callFunction({
        name: 'login',
        data: {}
      }).then(res => {
        Vue.prototype.database.collection('user').where({
          openid: res.result.openid
        }).get().then(result => {
          if (result.data.length > 0) {
            Vue.prototype.$store.commit('getUser', result.data[0]);
            console.log(result.data)
          } else {
            Vue.prototype.$store.commit('setOpenId', res.result.openid);
          }
          wx.hideLoading()
        })
      });
    },
    log() {
      console.log(`log at:${Date.now()}`)
    }
  }
</script>

<style>
  .container {
    height: 100%;
  }

  /* this rule will be remove */
  * {
    transition: width 2s;
    -moz-transition: width 2s;
    -webkit-transition: width 2s;
    -o-transition: width 2s;
  }
</style>
